package com.collabscm.pf.persistence;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import com.collabscm.pf.AbstractTestCase;
import com.collabscm.pf.util.ObjectUtils;
import com.collabscm.pf.vo.QueryParameters;

@ContextConfiguration(locations={"classpath:config/application-config.xml"})
public class TestDynamicQueryBuilder extends AbstractTestCase {
	@Autowired
	private DynamicQueryBuilder builder;

	@Test
	public void test() {
		String dynamicQuery = "select * from TT t where @t.attr1=:attr1 and @t.attr2=:attr2 and @t.attr3=:attr3";
		QueryParameters parameters = new QueryParameters();
		parameters.addFilter("attr2", "value2");
		parameters.addFilter("attr1", "value1");
		parameters.setOrder("a.attr2", true);
		DynamicQuery dq = builder.buildByDynamicNativeQuery(dynamicQuery, WhereJoinType.AND, parameters);
		logger.debug("查询语句为{}，计算总数的语句为{}，参数列表为：{}", dq.getQueryStatement(), dq.getCountStatement(), ObjectUtils.toString(dq.getFilters()));
	}
}
